package br.edu.ufcg.p1.barzin.async;

import static br.edu.ufcg.p1.barzin.util.PrefManConstants.TABLET_ID;
import android.os.AsyncTask;
import br.edu.ufcg.p1.barzin.App;
import br.edu.ufcg.p1.barzin.event.EventBus;
import br.edu.ufcg.p1.barzin.event.MesasMsgsEvento;
import br.edu.ufcg.p1.barzin.model.MensagensNovas;
import br.edu.ufcg.p1.barzin.util.HTTPCalls;

public class MesaMsgsTask extends AsyncTask<Integer, Integer, MensagensNovas> {

	@Override
	protected MensagensNovas doInBackground(Integer... versaoCardapio) {
		Integer idTablet = App.environment().getSharedPreferences()
				.getInt(TABLET_ID, -1);

		MensagensNovas total = HTTPCalls.recuperaMsgsNovas(idTablet);

		return total;
	}

	@Override
	protected void onPostExecute(MensagensNovas result) {
		if (result != null) {
			EventBus.getInstance().publica(new MesasMsgsEvento(result));
		}
	}

}
